package cn.tyz.kotlin.glide

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import cn.tyz.kotlin.model.MovieList
import cn.tyz.kotlin.R
import kotlinx.android.synthetic.main.item_imagelist_layout.view.*

/**
 * @author : tianyingzhong
 * @ClassName: MovieListAdapter
 * @Description:  http://blog.csdn.net/hexingen/article/details/72970807
 * @time 2017/8/23 20:06
 */

internal class MovieListAdapter(var context: Context, var list: List<MovieList.Movie>) : RecyclerView.Adapter<MovieListAdapter.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int)
            = MovieListAdapter.ViewHolder(View.inflate(parent.context, R.layout.item_imagelist_layout, null))

    override fun onBindViewHolder(holder: MovieListAdapter.ViewHolder, position: Int) {
        //调用Java编写静态方法
        GlideUtils.loadUrlImage(context,list[position].images.large,holder.imagelist_iv)
    }
    override fun getItemCount() = list.size

    internal class ViewHolder(rootView: View) : RecyclerView.ViewHolder(rootView) {
        /**
         * 这里使用Kotlin Android 扩展，省略了findViewById（）.
         * 在最上面导入了import kotlinx.android.synthetic.main.movielist_item.view.*
         */
        var imagelist_iv = rootView.imagelist_iv
        var imagelist_title= rootView.imagelist_title
    }
}